package cn.com.computer.my.book.web;

import cn.com.computer.common.base.bean.CandyResult;
import cn.com.computer.common.utils.helper.ParamUtils;
import cn.com.computer.my.book.service.OriginalRaidersBookService;
import cn.com.computer.my.book.web.bean.OriginalRaidersBookBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Created by WANGXin on 2017/5/21.
 */
@Controller
@RequestMapping(value = "/raider/book")
public class RaidersBookController {

    private static final Logger LOGGER = LoggerFactory.getLogger(RaidersBookController.class);

    @Autowired
    private OriginalRaidersBookService originalRaidersBookService;

    /**
     * 保存攻略书信息
     * @param originalRaidersBookBean
     * @return
     */
    @RequestMapping(value = "/commit/save", method = RequestMethod.POST)
    @ResponseBody
    public CandyResult saveRaiderBook(OriginalRaidersBookBean originalRaidersBookBean,
                                      HttpServletRequest request,
                                      HttpServletResponse response) {
        CandyResult candyResult = new CandyResult();

        try {
            candyResult = originalRaidersBookService.saveRaiderBook(originalRaidersBookBean);
        }catch (Exception e){
            LOGGER.error("保存攻略书信息异常，异常数据为:[" + ParamUtils.serializable(originalRaidersBookBean) + "]",e);
            candyResult.setMessage("保存攻略书信息失败");
        }

        return candyResult;
    }

}
